package org.tooyoung.fourone.live.adapters;


import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import org.tooyoung.fourone.R;
import org.tooyoung.fourone.live.ImageUtils.CircleImage;
import org.tooyoung.fourone.live.models.Fan;

import java.util.List;

public class MyFanListAdapter extends RecyclerView.Adapter<MyFanListAdapter.FanViewHolder>{
    private Context context;
    private List<Fan> list;

    public MyFanListAdapter(Context context, List<Fan> list) {
        this.context = context;
        this.list = list;
    }
    void setList(List<Fan> list)
    {
        this.list=list;
    }

    @Override
    public FanViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.live_head_item, parent, false);
        FanViewHolder fanViewHolder = new FanViewHolder(view);
        return fanViewHolder;
    }

    @Override
    public void onBindViewHolder(FanViewHolder holder, int position) {
        Picasso.with(holder.live_head_list_iv.getContext())
                .load(list.get(position).getHeadimg())
                .config(Bitmap.Config.RGB_565)
                .placeholder(R.mipmap.default_head_light)
                .error(R.mipmap.default_head_light)
                .transform(new CircleImage())
                .into(holder.live_head_list_iv);
    }

    @Override
    public int getItemCount() {
        int ret =0;
        if (list != null) {
            ret=list.size();
        }
        return ret;
    }

    public static class FanViewHolder extends RecyclerView.ViewHolder
    {
        private ImageView live_head_list_iv;
        public FanViewHolder(View itemView) {
            super(itemView);
            live_head_list_iv= (ImageView) itemView.findViewById(R.id.live_head_list_iv);
        }
    }
}
